if TUNING.NPC_UPGRADE_ITEMS_FN == nil then
    TUNING.NPC_UPGRADE_ITEMS_FN = {}
end


local function Fn()
    local Fx = Class()

    
    local function GetStringsTable()
        return TUNING.NPC_CHAT_TABLE[ type(TUNING.__NPC_LANGUAGE)=="function" and TUNING.__NPC_LANGUAGE() or TUNING.__NPC_LANGUAGE ] ["flowerhat_upgrade"] or {}
    end

    function Fx:upgrade_flower_step(inst)

        inst.components.named:SetName(GetStringsTable().name_flower_step)
        
        inst.components.equippable.dapperness = -TUNING.CRAZINESS_MED*3
	    inst.components.equippable.is_magic_dapperness = true
        inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST/3)
        ---------------------------------------------------------------------------
        ------ 鲜花环绕特效
        inst.plantpool = { 1, 2, 3, 4 }
        for i = #inst.plantpool, 1, -1 do
            --randomize in place
            table.insert(inst.plantpool, table.remove(inst.plantpool, math.random(i)))
        end
    
        local function PlantTick(inst)
            if not inst:IsValid() and inst.planttask then
                inst.planttask:Cancel()
                return
            end
            local pt = inst.npc_base_lib:GetSpawnPoint(inst,math.random(25)/10)
            if pt == nil then
                pt = Vector3(inst.Transform:GetWorldPosition())
            end
            local plant = SpawnPrefab("npc_fx_flowers_of_wormwood")
            plant.Transform:SetPosition(pt.x,0,pt.z)
            local rnd = math.random()
                rnd = table.remove(inst.plantpool, math.clamp(math.ceil(rnd * rnd * #inst.plantpool), 1, #inst.plantpool))
            table.insert(inst.plantpool, rnd)
            plant:SetVariation(rnd)
        end
        inst.planttask = inst:DoPeriodicTask(.25, PlantTick)
        --------------------------------------------------------------------------
    end

    
    return Fx
end


if TUNING.NPC_UPGRADE_ITEMS_FN["flowerhat"] == nil then    
    TUNING.NPC_UPGRADE_ITEMS_FN["flowerhat"] = Fn
end
